import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main20250316 {
}

class Solution {
    public int largestVariance(String s) {
        int[][] dp = new int[s.length()][s.length()];
        List<int[]> list = new ArrayList<>();
        int[] p = new int[26];
        list.add(new int[26]);
        for (int i = 1; i < s.length() + 1; i++) {
            p[s.charAt(i - 1) - 'a']++;
            list.add(p);
            p = Arrays.copyOf(p, p.length);
            //System.out.println(Arrays.toString(list.get(i)));
        }
        int max = 0;
        for (int i = 0; i < s.length(); i++) {
            for (int j = i + 1; j < s.length(); j++) {
                //到j为止的所有字符数量到i-1之前的所有字符数量
                //System.out.println(Arrays.toString(list.get(j+1)));
                //System.out.println(Arrays.toString(list.get(i)));
                max = Math.max(max, sub(list.get(j + 1), list.get(i)));
            }
        }
        return max;
    }

    private int sub(int[] ints, int[] ints1) {
        int max = 0, min = 0;
        for (int i = 0; i < ints.length; i++) {
            int x = ints[i] - ints1[i];
            x = Math.max(x, 0);
            if (x > max) {
                max = x;
            }
            if (min == 0) {
                min = x;
            } else if (x != 0 && x < min) {
                min = x;
            }
        }
        //System.out.println(max+" "+min);
        return max - min;
    }
}